
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpgradeOverhealing:Upgrade {

	protected override void SubscribeEvents() {
		base.SubscribeEvents();
		MobEventHelper.lateDamage.SubscribeSingle(weapon.owner,Mob_LateDamage);
	}
	public override void UnsubscribeEvents() {
		base.UnsubscribeEvents();
		MobEventHelper.lateDamage.UnsubscribeSingle(weapon.owner,Mob_LateDamage);
	}
	void Mob_LateDamage(object sender,DamageEventArgs e) {
		if(e.stat.damageType!=DamageType.Healing) return;
		float healAmount = -e.stat.amount;
		float hpRemaining = weapon.owner._maxHP-weapon.owner.HP;
		if(hpRemaining>=healAmount) return;
		if(weapon.owner.buffs[typeof(BuffDamageShield)].stacks>=4) return;
		weapon.owner.buffs[typeof(BuffDamageShield)].stacks=Mathf.Min(4,weapon.owner.buffs[typeof(BuffDamageShield)].stacks+(healAmount-hpRemaining)*0.1f);
	}

}
